namespace Crux.Core.EasyNetQ;
/// <summary>
/// EasyNetQInitializer
/// </summary>
public class EasyNetQInitializer(IRabbitMqBusAccessor accessor)
{
    private readonly IRabbitMqBusAccessor _accessor = accessor ?? throw new ArgumentNullException(nameof(accessor));
    /// <inheritdoc/>
    public AutoSubscriber InitAutoSubscriber(
        string prefix,
        params Type[] type)
    {
        var bus = _accessor.TryGetBus();

        var subscriber = new AutoSubscriber(bus, prefix);

        subscriber.SubscribeAsync(type);

        return subscriber;
    }
    /// <inheritdoc/>
    public AutoSubscriber InitAutoSubscriber(
        string prefix,
        IAutoSubscriberMessageDispatcher dispatcher,
        params Type[] type)
    {
        var bus = _accessor.TryGetBus();

        var subscriber = new AutoSubscriber(bus, prefix)
        {
            AutoSubscriberMessageDispatcher = dispatcher
        };

        subscriber.SubscribeAsync(type);

        return subscriber;
    }

}